-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for custom types #36
Conversation
Hi! As I mentioned on the Elixir forum, I'm a big fan of your work, and I'd like to get some insight into your thoughts when starting a new library like this one. Specifically, I'm interested in your reasons for making each custom type into its own module instead of defining them as functions like this: defmodule UserContract do
use Drops.Contract
def filled_string do
Drops.Type.define({:string, [:filled?]})
end
schema do
%{
required(:name) => filled_string()
}
end
end EDIT: I guess the function syntax could be improved a bit |
@Sorc96 thank you. We need explicit type modules so that it's easier to implement PM-based logic as well as various protocol implementations. If a type was a single struct type, things would get hairy quickly. ie there's already an issue with handling maps because they are too complex, and I clearly see a need for In general, types are infinitely complex and they must be composable too 😅 I'm modeling things here in a similar way like in dry-types in Ruby, where it works really well. Luckily here, we can just use structs, functions and PM, which is so much simpler and better than complex inheritance hierarchies and various decoration techniques! Does this makes sense to you? |
@solnic Thanks for the explanation! |
611d2ab
to
163d8a4
Compare
d430bef
to
f34684e
Compare
This adds support for defining custom types
Types are regular structs: